//
//  MainTabBarController.m
//  bitcoin
//
//  Created by caiyajun on 2018/4/25.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "MainTabBarController.h"
#import "LoginController.h"
#import "MarketViewController.h"
#import "KLTNavigationController.h"
#import "TradeViewController.h"

@interface MainTabBarController ()<UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.tabBarController.selectedIndex = 0;
    

    self.delegate = self;
    self.tabBar.translucent = NO;
    self.tabBar.tintColor = RGBColor(89, 119, 234);
    if (iPhoneX) {
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen  mainScreen].bounds.size.width, 83)];
        backView.backgroundColor = RGBColor(46, 49, 69);
        [self.tabBar insertSubview:backView atIndex:0];
        
    }else{
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen  mainScreen].bounds.size.width, 49)];
        backView.backgroundColor = RGBColor(46, 49, 69);
        [self.tabBar insertSubview:backView atIndex:0];
        
    }
    
    self.tabBar.opaque = YES;
    
    
    
    
    
    BaseNavigationController *home = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateInitialViewController];
    
    //BaseNavigationController *market = [[UIStoryboard storyboardWithName:@"Market" bundle:nil] instantiateInitialViewController];
    MarketViewController *market = [[MarketViewController alloc]init];
    market.menuViewStyle = WMMenuViewStyleLine;
    market.title = @"行情";
    KLTNavigationController *marketNav = [[KLTNavigationController alloc]initWithRootViewController:market];
    
    TradeViewController *trade = [[TradeViewController alloc]init];
    
    trade.tabBarItem.title = @"交易";
    KLTNavigationController *tradeNav = [[KLTNavigationController alloc]initWithRootViewController:trade];
    
//    BaseNavigationController *trade = [[UIStoryboard storyboardWithName:@"Trade" bundle:nil] instantiateInitialViewController];
    BaseNavigationController *me = [[UIStoryboard storyboardWithName:@"Me" bundle:nil] instantiateInitialViewController];
    
    
    [self addChildViewController: home];
    [self addChildViewController: marketNav];
    [self addChildViewController: tradeNav];
    [self addChildViewController: me];
    
    
    NSDictionary *dictHome = [NSDictionary dictionaryWithObject:RGBColor(153,153,153) forKey:NSForegroundColorAttributeName];
    NSDictionary *selsctedHome = [NSDictionary dictionaryWithObject:RGBColor(255,174,29) forKey:NSForegroundColorAttributeName];
    
    
    
    UITabBarItem *item0 = home.tabBarItem;
    item0.tag = 21;
    item0.selectedImage = [[UIImage imageNamed:@"homeactive-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    item0.image = [[UIImage imageNamed:@"home-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [item0 setTitleTextAttributes:selsctedHome forState:UIControlStateSelected];
    [item0 setTitleTextAttributes:dictHome forState:UIControlStateNormal];
    
    UITabBarItem *item1= market.tabBarItem;
    item1.tag = 22;
    item1.selectedImage = [[UIImage imageNamed:@"Quotationactive-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    item1.image = [[UIImage imageNamed:@"Quotation-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [item1 setTitleTextAttributes:selsctedHome forState:UIControlStateSelected];
    [item1 setTitleTextAttributes:dictHome forState:UIControlStateNormal];
    
    
    UITabBarItem *item2= trade.tabBarItem;
    item2.tag = 23;
    item2.selectedImage = [[UIImage imageNamed:@"transactionactive-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item2.image = [[UIImage imageNamed:@"transaction-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [item2 setTitleTextAttributes:selsctedHome forState:UIControlStateSelected];
    [item2 setTitleTextAttributes:dictHome forState:UIControlStateNormal];
    
    UITabBarItem *item3= me.tabBarItem;
    item3.tag = 24;
    item3.selectedImage = [[UIImage imageNamed:@"myactive-icon"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item3.image = [[UIImage imageNamed:@"my-icon 拷贝"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [item3 setTitleTextAttributes:selsctedHome forState:UIControlStateSelected];
    [item3 setTitleTextAttributes:dictHome forState:UIControlStateNormal];
    
    
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    if (item.tag == 23) {//交易
        //弹出登录页面
//        BaseNavigationController *base = [[UIStoryboard storyboardWithName:@"Login" bundle:nil] instantiateInitialViewController];
//        [self presentViewController:base animated:NO completion:nil];

    }
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
//    if ([viewController isKindOfClass:[UINavigationController class]]) {
//        
//        UINavigationController *nav = (UINavigationController*)viewController;
//        if ([nav.visibleViewController isKindOfClass:[MarketViewController class]]) {
//            [((MarketViewController*)nav.visibleViewController) getData];
//        }
//        
//    }
}

@end
